<?php
namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;

class Im extends NotORM {
	/* 系统通知 */
	public function getSysNotice($uid,$p) {
		
        if($p<1){
            $p=1;
        }
		$pnum=50;
		$start=($p-1)*$pnum;
        
        $where=[];
        $where['touid=0 or touid=?']=$uid;
        if($uid){
            $userinfo=\PhalApi\DI()->notorm->user
					->select("create_time")
					->where('id=?',$uid)
					->fetchOne();
            if($userinfo){
                $where['addtime>?']=$userinfo['create_time'];
            }
        }
        
		$list=\PhalApi\DI()->notorm->sys_notice
					->select("*")
					->where($where)
					->limit($start,$pnum)
                    ->order('id desc')
					->fetchAll();
		
		return $list;

	}


	/* 获取私信限制 */
	public function getlimit($uid) {
        
		$info=\PhalApi\DI()->notorm->im_limit
					->select("*")
					->where('uid=?',$uid)
					->fetchOne();
		
		return $info;

	}

	/* 新加限制 */
	public function setlimit($data) {
        
		$rs=\PhalApi\DI()->notorm->im_limit->insert($data);
		
		return $rs;

	}

	/* 更新限制 */
	public function uplimit($uid,$data) {
        
		$list=\PhalApi\DI()->notorm->im_limit
					->where('uid=?',$uid)
					->update($data);
		
		return $list;

	}

	/* 更新次数 */
	public function addlimit($uid) {
        
		$rs=\PhalApi\DI()->notorm->im_limit
					->where('uid=?',$uid)
					->update(array('times' => new \NotORM_Literal("times + 1") ) );
		
		return $rs;

	}
    
		

}
